const sqlite3 = require('sqlite3').verbose();
const path = require('path');

const dbPath = path.join(__dirname, 'data', 'pph.sqlite');
const db = new sqlite3.Database(dbPath);

console.log('🔍 检查PPH记录表结构...');

// 查询表结构
db.all("PRAGMA table_info(pph_records)", (err, columns) => {
    if (err) {
        console.error('❌ 表结构查询失败:', err);
    } else {
        console.log(`\n🏗️ PPH记录表字段列表 (共 ${columns.length} 个字段):`);
        columns.forEach(col => {
            const nullable = col.notnull === 0 ? 'NULL' : 'NOT NULL';
            const defaultVal = col.dflt_value ? ` DEFAULT ${col.dflt_value}` : '';
            console.log(`  ${col.cid.toString().padStart(2)}: ${col.name.padEnd(25)} ${col.type.padEnd(15)} ${nullable}${defaultVal}`);
        });
        
        // 专门检查目标值相关字段
        const targetFields = columns.filter(col => 
            col.name.includes('target') || 
            col.name.includes('estimate') || 
            col.name.includes('efficiency') ||
            col.name.includes('pph')
        );
        
        console.log(`\n🎯 目标值相关字段 (共 ${targetFields.length} 个):`);
        targetFields.forEach(col => {
            console.log(`  ✓ ${col.name}: ${col.type}`);
        });
    }
    db.close();
});
